<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="${pageContext.request.contextPath}/jQuery-Validation/css/validationEngine.jquery.css" rel="stylesheet">
<style type="text/css">
body{background:#fff;}
		.contain{width:520px; margin:150px auto; background: #F4F4F4; color:#636864; padding-bottom: 30px;}
			.accountPay{padding:10px 40px;}
			.accountPay label,.accountPay span:nth-child(1){display: inline-block;width:120px;}
			.accountPay input{width: 250px; height:33px; background: #fff !important; line-height: 33px; border:1px solid #ddd; padding-left: 10px;}
			.accountPay button{width:160px; color: #fff; background: #31DDDB; height:42px; border-radius: 5px; font-size: 15px; border:0;}
			.contain h2{border-bottom:1px solid #ddd; font-size: 16px; height:30px; line-height: 30px;  padding: 10px;}
	</style>
</head>
<body>
<shiro:hasRole name="admin">
	<div class="contain" style="display:none;">
		<h2>提现</h2>
		<div>
			<div class="accountPay">
				<span>账户余额：</span>
				<span id="balance"></span><span> 元</span>
			</div>
			<div class="accountPay">
				<span>账户号：</span>
				<span id="accountNo"></span>
			</div>
			<div class="accountPay">
				<span>开户行：</span>
				<span style="margin-right:10px;" id="bankName"></span>
			</div>
			<div class="accountPay">
				<span>银行卡号：</span>
				<span id="bankCard"></span>
			</div>
		</div>
		<form class="form-horizontal" role="form" id="withdrawFrom" autocomplete="off">
			<div class="accountPay">
				<label>提现金额：</label>
				<input type="text" id="tBalance" class="validate[required,custom[floatingNumber]]" placeholder="提现金额如：100.58" autocomplete="off"><span> 元</span>
			</div>
			<div class="accountPay">
				<label>提现密码：</label>
				<input type="password" id="wdPwd" maxlength="6" class="validate[required,minSize[6],maxSize[6],custom[onlyNumberSp]]" placeholder="请输入提现密码" autocomplete='new-password' 
				>
			</div>
			<div class="accountPay" style="text-align:center; margin-top:25px;" autocomplete="off">
				<button type="submit" id="withdrawBtn" style="cursor: pointer;">确认提现</button>
			</div>
		</form>
	</div>
</shiro:hasRole>
<shiro:lacksRole name="admin">
	<div style="width: 600px;margin: 200px auto;">
		<img src="${pageContext.request.contextPath}/img/quanxian.png" width="600px">
	</div>
</shiro:lacksRole>
<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/jQuery-Validation/js/jquery.validationEngine.js"></script>
<script src="${pageContext.request.contextPath}/jQuery-Validation/js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript">
<shiro:hasRole name="admin">
var isHaveWdPwd = true;	//是否有提现密码
var isCanWithraw = true;	//提现按钮是否位可用标识
$(function () {
	checkIsHasWdPwd();
	queryBankCardAndNameByNum();
	//如果不能提现，则设置按钮样式
	if(isCanWithraw == false){
		$('#withdrawBtn').attr('disabled', true);
		return;
	}
	//验证是否都符合
	$('#withdrawFrom').validationEngine('attach', {
	    validationEventTrigger : 'blur',	//当提交的时候验证是否合法
	    promptPosition: 'topRight',
	    scroll: false,
	    focusFirstField : true,
	    autoPositionUpdate:true,
	    onValidationComplete : function (form, valid) {
	    	if(valid){
	    		withraw();
	    	}
	    }
	});
});

//检测该企业是否设置提现密码
function checkIsHasWdPwd(){
	$.ajax({
		url: "../withdraw/checkWdPwd.htm",
		cache: false,
		async : false,
		type: "get",
		dataType: "json",
		beforeSend:function(){var index = layer.load(1, { shade: [0.8,'#ddd']});},
        complete:function(){var index = layer.closeAll("loading");},
		success: function (result) {
		    if (result.status == 60000) {	//如果返回值是1，则说明没有设置提现密码
		    	isHaveWdPwd = false;
		        layer.open({
		            type: 2,
		            title: '设置提现密码',
		            maxmin: false,	//最大最小化
		            shadeClose: false, //点击遮罩关闭层
		            shade: [1, '#ddd'],
		            area : ['300px' , '250px'],
		            content: '../withdraw/withdraw_pass.htm',
		            cancel:function(index, layero){	//点击右上角关闭按钮触发的回调，直接关闭此提现Tab
		            	$(window.parent.document).find(".page-tabs-content a.active").find("i").trigger("click");
		            },
		        	end: function(index, layero){ 
		        		  $(".contain").show();
		        	  return false; 
		        	}    
		        });
		    }else{
		    	 $(".contain").show(); 
		    }
		}
	});
}

//查询出银行卡信息
function queryBankCardAndNameByNum(){
	$.ajax({
		url: "../company/getBankCardAndNameByNum.htm",
		cache: false,
		async : false,
		type: "get",
		dataType: "json",
		beforeSend:function(){var index = layer.load(1, { shade: [0.8,'#ddd']});},
        complete:function(){var index = layer.closeAll("loading");},
		success: function (result) {
		    if (result.status == 0) {	//如果正常返回，则显示出值
		        var data = result.data;
		        $('#balance').text(data.balance);
                $('#accountNo').text(data.accountNo);
                $('#bankName').text(data.bankName);
                $('#bankCard').text(data.bankCard);
		    }else if(result.status == 1){
            	layer.msg(result.message, {icon: 7});
            	isCanWithraw = false;	//出现异常
            }else if(result.status == 401){	//如果无权限
            	layer.msg(result.message, {icon: 2});
            	isCanWithraw = false;	//出现异常
            }else if(result.status == 40000){	//如果参数有问题，则提示开户
            	layer.msg(result.message, {icon: 7});
            	isCanWithraw = false;	//出现异常
            }
		}
	});
}

//提现操作
function withraw(){
	var balance = Number($('#balance').text());
	var tBalance = Number($('#tBalance').val());
	if(tBalance > balance){
		layer.msg('提现金额不能大于账户余额', {icon: 2});
		return;
	}
	var accountNo = $('#accountNo').text();
	var amount = $('#tBalance').val();
	var wdPwd = $('#wdPwd').val();
	//提现ajax
	$.ajax({
		url: "../withdraw/withdraw.htm",
		cache: false,
		async : false,
		type: "post",
		dataType: "json",
		data: {"wdPassword":wdPwd, "accountNo":accountNo, "amount":amount},
		beforeSend:function(){var index = layer.load(1, { shade: [0.8,'#ddd']});},
        complete:function(){var index = layer.closeAll("loading");},
		success: function (result) {
		    if (result.status == 0) {	//如果正常返回，则显示出值
		        var data = result.data;
		        layer.msg(result.message, {icon: 1});
		    }else if(result.status == 1){
            	layer.msg(result.message, {icon: 7});
            }else if(result.status == 401){	//如果无权限
            	layer.msg(result.message, {icon: 2});
			    return;
            }
		}
	});
}
</shiro:hasRole>
</script>
</body>
</html>